import requests,json
import pandas as pd
key = "dcf6ab6ec2715890c639887ab32bfc87"
-----
# 地理编码
def geocode(key,address,city=None,batch="false",sig=None,output="json",callback=None):
    """将详细的结构化地址转换为高德经纬度坐标"""
    geocode_url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    params = {
        "key":key,
        "address":address,
        "city":city,
        "batch":batch,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(geocode_url,params=params)
    results = r.json()
    return results

-----
# 逆地理编码函数
def regeo(key,location,extensions="base",radius=None,poitype=None):
     """将经纬度转换为详细结构化的地址，且返回附近周边的POI、AOI信息"""
    url = "https://restapi.amap.com/v3/geocode/regeo?parameters"
    params = {
        "key":key,
        "location":location,
        "extensions":extensions,
        "radius":radius,
        "poitype":poitype
    }
    r = requests.get(url,params)
    results = r.json()
    return results

-----
# 步行路径规划
def walking(key,origin,destination,sig=None,output="json",callback=None):
    """步行路径规划 API 可以规划100KM以内的步行通勤方案，并且返回通勤方案的数据"""
    walking_url = "https://restapi.amap.com/v3/direction/walking?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(walking_url,params=params)
    results = r.json()
    return results

----
# 公交车路径规划
def bus(key,origin,destination,city):
     """公交路径规划 API 可以规划综合各类公共（火车、公交、地铁）交通方式的通勤方案，并且返回通勤方案的数据。"""
    bus_url = "https://restapi.amap.com/v3/direction/transit/integrated?parameters"
    params ={
        "key":key,
        "origin":origin,
        "destination":destination,
        "city":city
    }
    r = requests.get(bus_url,params=params)
    result = r.json()
    return result


------
# 行政区域查询
def xzqu(key='base',keywords='base',subdistrict=None,page=None,extensions='base',filter=None):
     """根据用户输入的搜索条件可以帮助用户快速的查找特定的行政区域信息"""
    xzqy_url = "https://restapi.amap.com/v3/config/district?parameters"
    params ={
        'key':key,
        'keywords':keywords,
        'subdistrict':subdistrict,
        'page':page,
        'extensions':extensions,
        'filter':filter
    }
    r = requests.get(xzqy_url,params=params)
    result = r.json()
    return result


-----
# 搜索POI
# 关键字搜索
def POI01(key='base',keywords='base',types=None,city=None,extensions='all',citylimit=None,children=None,offset=None,page=None):
    """通过用POI的关键字进行条件搜索，例如：肯德基、朝阳公园等；同时支持设置POI类型搜索，例如：银行"""
    POI01_url = "https://restapi.amap.com/v3/place/text?parameters"
    params ={
        'key':key,
        'keywords':keywords,
        'types':types,
        'city':city,
        'children':children,
        'offset':offset,
        'page':page,
        'extensions':extensions
    }
    r = requests.get(POI01_url,params=params)
    result = r.json()
    return result

# 周边搜索
def POI02(key='base',location='base',keywords='base',types=None,radius=None,extensions='all',offset=None,page=None):
     """在用户传入经纬度坐标点附近，在设定的范围内，按照关键字或POI类型搜索"""
    POI02_url = "https://restapi.amap.com/v3/place/around?parameters"
    params ={
        'key':key,
        'keywords':keywords,
        'types':types,
        'location':location,
        'radius':radius,
        'offset':offset,
        'page':page,
        'extensions':extensions
    }
    r = requests.get(POI02_url,params=params)
    result = r.json()
    return result

# 多边形搜索
def POI03(key='base',polygon='base',keywords='base',types=None,extensions='all',offset=None,page=None):
    POI03_url = "https://restapi.amap.com/v3/place/polygon?parameters"
    params ={
        'key':key,
        'keywords':keywords,
        'types':types,
        'polygon':polygon,
        'offset':offset,
        'page':page,
        'extensions':extensions
    }
    r = requests.get(POI03_url,params=params)
    result = r.json()
    return result

----
# ip定位
def ipya(key="base",ip=None,info=None,status=None,province=None,infocode=None,city=None,adcode=None,rectangle=None):
     """根据用户输入的IP地址，能够快速的帮用户定位IP的所在位置"""
    url = 'https://restapi.amap.com/v3/ip?parameters'
    params = {
    'key':key,
    'ip':ip,
    'status':status,
    'info':info,
    'infocode':infocode,
    'province':province,
    'city':city,
    'adcode':adcode,
    'rectangle':rectangle
    
  
}
    r = requests.get(url,params)
    result = r.json()
    return result

-----
# 静态地图
def jtdt(key="base",location=None,zoom=None,size=None,scale=None,markers=None,labels=None,paths=None,traffic=None):
    """静态地图服务通过返回一张地图图片响应HTTP请求，使用户能够将高德地图以图片形式嵌入自己的网页中。用户可以指定请求的地图位置、图片大小、以及在地图上添加覆盖物，如标签、标注、折线、多边形。"""
    url = 'https://restapi.amap.com/v3/staticmap?parameters'
    params = {
    'key':key,
    'location':location,
    'zoom':zoom,
    'size':size,
    'scale':scale,
    'markers':markers,
    'labels':labels,
    'paths':paths,
    'traffic':traffic
  
}
    r = requests.get(url,params=params)
    results = Image.open(BytesIO(r.content))
    return results

----
# 坐标转换
def zbzh(key,coordinate_convert_location,coordsys="autonavi",sig=None,output="json"):
    """将用户输入的非高德坐标（GPS坐标、mapbar坐标、baidu坐标）转换成高德坐标"""
    coordinate_convert_url = "https://restapi.amap.com/v3/assistant/coordinate/convert?parameters"
    params = {
        "key":key,
        "locations":coordinate_convert_location,
        "coordsys":coordsys,
        "sig":sig,
        "output":output
    }
    r = requests.get(coordinate_convert_url,params=params)
    results = r.json()
    return results

-----
# 天气查询
def weather(key,city,extension="all",output="json"):
    """根据用户输入的adcode，查询目标区域当前/未来的天气情况"""
    weather_url = "https://restapi.amap.com/v3/weather/weatherInfo?parameters"
    params = {
        "key":key,
        "city":city,
        "extensions":extension,
        "output":output
    }
    r = requests.get(weather_url,params=params)
    results = r.json()
    return results


-----
#  输入提示
def inputtips(key,keyword,input_type=None,location=None,city=None,citylimit="false",datatype="all",sig=None,output="json",callback=None):
    """提供根据用户输入的关键词查询返回建议列表"""
    inputtips_url = "https://restapi.amap.com/v3/assistant/inputtips?parameters"
    params = {
        "key":key,
        "keywords":keyword,
        "type":input_type,
        "location":location,
        "city":city,
        "citylimit":citylimit,
        "datatype":datatype,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(inputtips_url,params=params)
    results = r.json()
    return results

------
# 交通态势
# 矩形区域交通
def traffic_rectangle(key,rectangle,level=5,extensions="base",sig=None,output="json",callback=None):
    """提供根据用户输入的内容能够返回希望查询的交通态势情况"""
    traffic_rectangle_url = "https://restapi.amap.com/v3/traffic/status/rectangle?parameters"
    params = {
        "key":key,
        "rectangle":rectangle,
        "level":level,
        "extensions":extensions,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(traffic_rectangle_url,params=params)
    results = r.json()
    return results


# 圆形区域交通态势
def traffic_circle(key,traffic_circle_location,level=5,extensions="base",sig=None,output="json",callback=None,radius=1000):
    """提供根据用户输入的内容能够返回希望查询的交通态势情况"""
    traffic_circle_url = "https://restapi.amap.com/v3/traffic/status/circle?parameters"
    params = {
        "key":key,
        "location":traffic_circle_location,
        "level":level,
        "extensions":extensions,
        "sig":sig,
        "output":output,
        "callback":callback,
        "radius":radius
    }
    r = requests.get(traffic_circle_url,params=params)
    results = r.json()
    return results

# 指定线路交通态势
def traffic_road(key,name,city,adcode=None,level=5,extensions="base",sig=None,output="json",callback=None):
    """提供根据用户输入的内容能够返回希望查询的交通态势情况"""
    traffic_road_url = "https://restapi.amap.com/v3/traffic/status/road?parameters"
    params = {
        "key":key,
        "name":name,
        "city":city,
        "adcode":adcode,
        "level":level,
        "extensions":extensions,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(traffic_road_url,params=params)
    results = r.json()
    return results
